import os
from configparser import ConfigParser


def get_mysql_db_info(layer: int):
    '''
    获取配置文件中的 host, port, username, password, db_name
    :return:
    '''
    parser = ConfigParser()
    if layer == 0:
        parser.read('static/mysql-db.cfg')
    elif layer == 1:
        parser.read('{}/static/mysql-db.cfg'.format(os.path.pardir))
    section = 'DEFAULT'
    return parser.get(section, 'host'), int(parser.get(section, 'port')), \
           parser.get(section, 'user'), parser.get(section, 'password'), parser.get(section, 'db_name')

